// 加载 yaml 环境变量文件
import { parse } from 'yaml';
import * as fs from 'fs';
import { join } from 'path';

const PRO_PATH = join(process.cwd(), '/.pro.yaml');
const DEV_PATH = join(process.cwd(), '/src/.dev.yaml');

export const getConfig = () => {
  let envName = process.env.NODE_ENV || 'dev';

  if (envName === 'production') envName = 'pro';

  const proPath = PRO_PATH;

  const devPath = DEV_PATH;
  const resPath = envName === 'pro' ? proPath : devPath;

  const envFile = fs.readFileSync(resPath, {
    encoding: 'utf-8',
  });
  const config = parse(envFile);
  return config;
};

export const getProConfig = () => {
  const envFile = fs.readFileSync(PRO_PATH, {
    encoding: 'utf-8',
  });
  const config = parse(envFile);
  return config;
};
